import CryptoJS from 'crypto-js'
export default {
    get(key: string) {
        const ciphertext = localStorage.getItem(key);
        if (ciphertext) {
            const bytes = CryptoJS.AES.decrypt(ciphertext, key);
            const plaintext = bytes.toString(CryptoJS.enc.Utf8);
            return JSON.parse(plaintext)
        } else {
            return ''
        }
    },
    set(key: string, val: string) {
        const ciphertext = CryptoJS.AES.encrypt(val, key).toString();
        localStorage.setItem(key, ciphertext)
    },
    remove(key: string) {
        localStorage.removeItem(key)
    },
    clear() {
        localStorage.clear()
    }
}